﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using XiaoGang.Soft.XGWMS.COM;

namespace XiaoGang.Soft.XGWMS.UI
{
    public partial class M009_STORAGE : FormBase
    {
        public M009_STORAGE()
        {
            InitializeComponent();
        }

        #region Delete By haoqiang 2008/09/03
        //private void InStoreForm_SizeChanged(object sender, EventArgs e)
        //{
        //    groupBox2.Width = this.Width - 50;
        //    groupBox2.Height = this.Height / 2 + 35;
        //    dataGridView1.Width = this.Width - 80;
        //    dataGridView1.Height = this.Height / 2 + 5;
        //}
        #endregion

        #region 変数の定義

        XGWMS.BLL.BLL_M009_STORAGE bll_STORAGE = 
            new XiaoGang.Soft.XGWMS.BLL.BLL_M009_STORAGE();
        XGWMS.BLL.BLL_M013_STORAGEOUTPUT bll_M013_STORAGEOUTPUT =
            new XiaoGang.Soft.XGWMS.BLL.BLL_M013_STORAGEOUTPUT();

        #endregion

        #region フォームの初期化する

        /// <summary>
        /// <p><b>メソッド名:</b>SetTabIndex</p>	
        /// <p><b>概要説明	:</b>画面フォーカスの遷移順の設定</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void SetTabIndex()
        {
            int intIndex = 0;
            grpInputStoreInfo.TabIndex = intIndex; intIndex++;
            txtGOODS_ID.TabIndex = intIndex; intIndex++;
            btnGoodsIDSearch.TabIndex = intIndex; intIndex++;
            txtGOODS_NM.TabIndex = intIndex; intIndex++;            
            cmbSTOREROOM_ID.TabIndex = intIndex; intIndex++;
            txtBUSINESS_TIME.TabIndex = intIndex; intIndex++;
            txtUNITS.TabIndex = intIndex; intIndex++;            
            rtbSTORAGEMEMO.TabIndex = intIndex; intIndex++;
            btnTempAdd.TabIndex = intIndex; intIndex++;

            grpTempBillInfo.TabIndex = intIndex; intIndex++;
            rtbBILLMEMO.TabIndex = intIndex; intIndex++;
            grpIN_OUT.TabIndex = intIndex; intIndex++;
            rabIN.TabIndex = intIndex; intIndex++;
            rabOUT.TabIndex = intIndex; intIndex++;
            grpRed_Black.TabIndex = intIndex; intIndex++;
            rabRed.TabIndex = intIndex; intIndex++;
            rabBlack.TabIndex = intIndex; intIndex++;
            btnAdd.TabIndex = intIndex; intIndex++;
            grdmentTempBillInfo.TabIndex = intIndex; intIndex++;            
        }
        /// <summary>
        /// <p><b>メソッド名:</b>SetEnable</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>概要説明  :</b>画面モードのセト</p>
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修正履歴  :</b></p>	
        /// </summary>
        private void SetEnable()
        {
            grpInputStoreInfo.Enabled = true;
            txtGOODS_ID.Enabled = true;
            btnGoodsIDSearch.Enabled = true;
            txtGOODS_NM.Enabled = true;
            rabIN.Enabled = true;
            rabOUT.Enabled = true;
            txtUNITS.Enabled = true;
            rabBlack.Enabled = true;
            rabRed.Enabled = true;
            txtBUSINESS_TIME.Enabled = true;
            cmbSTOREROOM_ID.Enabled = true;
            dtpBUSINESS_TIME.Enabled = true;
            rtbSTORAGEMEMO.Enabled = true;
            btnTempAdd.Enabled = true;

            grpTempBillInfo.Enabled = true;
            grdmentTempBillInfo.Enabled = true;
            btnAdd.Enabled = true;
        }
        /// <summary>
        /// <p><b>メソッド名:</b>ClearControl</p>	
        /// <p><b>概要説明	:</b>画面上の全項目をオールクリアする</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void ClearControl()
        {
            txtGOODS_ID.Text = ""; 
            txtGOODS_NM.Text = "";
            txtUNITS.Text = "";
            if (cmbSTOREROOM_ID.Items.Count != 0)
            {
                cmbSTOREROOM_ID.SelectedIndex = 0;
            }
            else
            {
                cmbSTOREROOM_ID.SelectedIndex = -1;
            }            
            rtbSTORAGEMEMO.Text = "";
            rtbBILLMEMO.Text = "";
            rabIN.Checked = false;
            rabOUT.Checked = false;
            rabBlack.Checked = false;
            rabRed.Checked = false;
        }
        /// <summary>
        /// <p><b>メソッド名:</b>InitComBox</p>	
        /// <p><b>概要説明	:</b>ComBoxの初期化する</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void InitComBox()
        {
            Method.CmbDataBound("STOREROOM_ID", cmbSTOREROOM_ID);           
            cmbSTOREROOM_ID.SelectedIndex = 0;    
        }
        /// <summary>
        /// <p><b>メソッド名:</b>InitGrid</p>	
        /// <p><b>概要説明	:</b>Gridの初期化する</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void InitGrid()
        {            
            grdmentTempBillInfo.ReadOnly = true;
            grdmentTempBillInfo.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            grdmentTempBillInfo.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
            grdmentTempBillInfo.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            grdmentTempBillInfo.ColumnHeadersHeight = 20;
            grdmentTempBillInfo.ColumnHeadersVisible = true;
            grdmentTempBillInfo.AllowUserToResizeColumns = true;
            grdmentTempBillInfo.ColumnHeadersDefaultCellStyle.Alignment =
                DataGridViewContentAlignment.MiddleCenter;

            grdmentTempBillInfo.Columns.Add("NO.", "NO.");
            grdmentTempBillInfo.Columns.Add("GOODS_ID", "商品编码");
            grdmentTempBillInfo.Columns.Add("GOODS_NM", "商品名称");
            grdmentTempBillInfo.Columns.Add("UNITS", "数量");
            grdmentTempBillInfo.Columns.Add("STOREROOM_ID", "仓库编号");
            grdmentTempBillInfo.Columns.Add("BUSINESS_TIME", "业务时间");
            DataGridViewButtonColumn btnDelete = new DataGridViewButtonColumn();
            btnDelete.Text = "删除";
            btnDelete.Width = 102;
            btnDelete.HeaderText = "删除";
            grdmentTempBillInfo.Columns.Add(btnDelete);
            grdmentTempBillInfo.Columns.Add("MEMO", "备注");

            grdmentTempBillInfo.Columns["NO."].Width = 30;
            grdmentTempBillInfo.Columns["NO."].Frozen = true;
            grdmentTempBillInfo.Columns["NO."].DefaultCellStyle.Alignment =
                DataGridViewContentAlignment.MiddleCenter;
            grdmentTempBillInfo.Columns["GOODS_ID"].Width = 98;
            grdmentTempBillInfo.Columns["GOODS_ID"].Frozen = true;
            grdmentTempBillInfo.Columns["GOODS_ID"].Resizable = DataGridViewTriState.False;
            grdmentTempBillInfo.Columns["GOODS_NM"].Width = 210;
            grdmentTempBillInfo.Columns["UNITS"].Width = 100;
            grdmentTempBillInfo.Columns["UNITS"].DefaultCellStyle.Alignment = 
                DataGridViewContentAlignment.MiddleRight;
            grdmentTempBillInfo.Columns["STOREROOM_ID"].Width = 98;
            grdmentTempBillInfo.Columns["BUSINESS_TIME"].Width = 120;
            grdmentTempBillInfo.Columns["MEMO"].Width = 126;
                  
            grdmentTempBillInfo.AllowUserToAddRows = false;
            grdmentTempBillInfo.AllowUserToDeleteRows = false;
            grdmentTempBillInfo.AllowUserToResizeRows = false;
            grdmentTempBillInfo.RowHeadersVisible = false;
            grdmentTempBillInfo.RowTemplate.Height = 20;
            grdmentTempBillInfo.RowTemplate.ReadOnly = true;
            grdmentTempBillInfo.RowTemplate.Resizable = DataGridViewTriState.False;
        }
        /// <summary>
        /// <p><b>メソッド名:</b>InitProcess</p>	
        /// <p><b>概要説明	:</b>フォームの初期化する</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// </summary>
        private void InitProcess()
        {
            SetTabIndex();
            SetEnable();
            InitGrid();
            InitComBox();
            ClearControl();
            txtBUSINESS_TIME.Text =
                dtpBUSINESS_TIME.Value.ToShortDateString();
        }

        #endregion

        #region Method
        /// <summary>
        /// <p><b>メソッド名:</b>CheckProcess</p>	
        /// <p><b>概要説明  :</b>画面のデータのＣＨＥＣＫ</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修正履歴  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strConstrolName">控件名称</param>	
        /// <returns type="Boolean">　True:成功   False:失敗 </returns>
        protected override bool CheckProcess(string strConstrolName)
        {
            switch (strConstrolName)
            {
                case "txtGOODS_ID":
                    if (Method.CheckIsNumber(txtGOODS_ID.Text.Trim(),
                        txtGOODS_ID.MaxLength,false,true) == false)
                    {
                        Method.MessageShow( GlobalVal.glostrMsg);
                        txtGOODS_ID.Focus();
                        txtGOODS_ID.SelectAll();
                        return false;
                    }
                    break;
                case "txtGOODS_NM":
                    if (0 == txtGOODS_NM.Text.Trim().Length)
                    {
                        Method.MessageShow("W11001");
                        txtGOODS_NM.Focus();
                        txtGOODS_NM.SelectAll();
                        return false;
                    }
                    if (Method.CheckIsIncludeSpecailChar(txtGOODS_NM.Text.Trim())
                        == false)
                    {
                        Method.MessageShow(GlobalVal.glostrMsg);
                        txtGOODS_NM.Focus();
                        txtGOODS_NM.SelectAll();
                        return false;
                    }
                    if (txtGOODS_NM.Text.Trim().Length > txtGOODS_NM.MaxLength)
                    {
                        Method.MessageShow("W11007");
                        txtGOODS_NM.Focus();
                        txtGOODS_NM.SelectAll();
                        return false;
                    }
                    break;
                case "txtUNITS":
                    string strTemp = txtUNITS.Text.Trim().Replace(",", "");
                    if (Method.CheckIsNumber(strTemp, txtUNITS.MaxLength, 
                        false, true) == false)
                    {
                        Method.MessageShow(GlobalVal.glostrMsg);
                        txtUNITS.Focus();
                        txtUNITS.SelectAll();
                        return false;
                    }
                    if (CheckUnits() == false)
                    {
                        return false;
                    }
                    break;
                case "cmbSTOREROOM_ID":
                    if (Method.CheckIsAllInputType(cmbSTOREROOM_ID.Text.Trim(), 50, false, true) == false)
                    {
                        cmbSTOREROOM_ID.Focus();
                        cmbSTOREROOM_ID.SelectAll();
                        Method.MessageShow(GlobalVal.glostrMsg);
                        return false;
                    }
                    break;
                case "txtBUSINESS_TIME":
                    if (CheckProcess(txtBUSINESS_TIME.Text.Trim(), enumCheckItems.DateYMD,
                        true, null) == false)
                    {
                        txtBUSINESS_TIME.Focus();
                        txtBUSINESS_TIME.SelectAll();
                        return false;
                    }
                    break;
                case "rtbMEMO":                    
                    if (Method.CheckIsIncludeSpecailChar(rtbSTORAGEMEMO.Text.Trim())
                        == false)
                    {
                        Method.MessageShow(GlobalVal.glostrMsg);
                        rtbSTORAGEMEMO.Focus();
                        rtbSTORAGEMEMO.SelectAll();
                        return false;
                    }
                    if (rtbSTORAGEMEMO.Text.Trim().Length > rtbSTORAGEMEMO.MaxLength)
                    {
                        Method.MessageShow("W11007");
                        rtbSTORAGEMEMO.Focus();
                        rtbSTORAGEMEMO.SelectAll();
                        return false;
                    }
                    break;
                case "rtbBILLMEMO":                    
                    if (Method.CheckIsIncludeSpecailChar(rtbBILLMEMO.Text.Trim())
                        == false)
                    {
                        Method.MessageShow(GlobalVal.glostrMsg);
                        rtbBILLMEMO.Focus();
                        rtbBILLMEMO.SelectAll();
                        return false;
                    }
                    if (rtbBILLMEMO.Text.Trim().Length > rtbBILLMEMO.MaxLength)
                    {
                        Method.MessageShow("W11007");
                        rtbBILLMEMO.Focus();
                        rtbBILLMEMO.SelectAll();
                        return false;
                    }
                    break;
                case "rabIN":
                    if (rabIN.Checked == true && rabOUT.Checked == true ||
                        rabIN.Checked == false && rabOUT.Checked == false)
                    {
                        Method.MessageShow("W11015");
                        rabIN.Select();
                        //rabIN.Focus();                     
                        return false;
                    }
                    break;
                case "rabOUT":
                    if (rabIN.Checked == true && rabOUT.Checked == true ||
                        rabIN.Checked == false && rabOUT.Checked == false)
                    {
                        Method.MessageShow("W11015");
                        rabOUT.Focus();                      
                        return false;
                    }
                    break;
                case "rabBlack":
                    if (rabBlack.Checked == true && rabRed.Checked == true ||
                        rabBlack.Checked == false && rabRed.Checked == false)
                    {
                        Method.MessageShow("W11015");
                        rabBlack.Focus();                     
                        return false;
                    }
                    break;
                case "rabRed":
                    if (rabBlack.Checked == true && rabRed.Checked == true ||
                        rabBlack.Checked == false && rabRed.Checked == false)
                    {
                        Method.MessageShow("W11015");
                        rabRed.Focus();
                        return false;
                    }
                    break;
            }

            return true;
        }
        /// <summary>	
        /// <p><b>メソッド名:</b>CheckProcessLoop</p>	
        /// <p><b>概要説明  :</b>画面のデータのＣＨＥＣＫ</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修正履歴  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strConstrolName">控件名称</param>	
        /// <returns type="Boolean">　True:成功   False:失敗 </returns>
        private bool CheckProcessLoop(enumOperation operation)
        {
            switch (operation)
            {
                case enumOperation.Initial:

                    if (CheckProcess("txtGOODS_ID") == false) return false;
                    if (CheckProcess("txtGOODS_NM") == false) return false;
                    if (CheckProcess("cmbSTOREROOM_ID") == false) return false;
                    if (CheckProcess("txtUNITS") == false) return false;
                    if (CheckProcess("rtbMEMO") == false) return false;
                    break;
                case enumOperation.Add:
                    if (CheckProcess("rtbBILLMEMO") == false) return false;
                    if (CheckProcess("rabIN") == false) return false;
                    if (CheckProcess("rabOUT") == false) return false;
                    if (CheckProcess("rabBlack") == false) return false;
                    if (CheckProcess("rabRed") == false) return false;
                    break;
            }
            return true;
        }
        /// <summary>	
        /// <p><b>メソッド名:</b>CheckUnits</p>	
        /// <p><b>概要説明  :</b>数量的Check</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/09</p>	
        /// <p><b>修正履歴  :</b></p>	
        /// </summary>
        /// <returns type="Boolean">　True:成功   False:失敗 </returns>
        protected bool CheckUnits()
        {
            MODEL.MOD_M009_STORAGE model = new XiaoGang.Soft.XGWMS.MODEL.MOD_M009_STORAGE();
            model.GOODS_ID = txtGOODS_ID.Text.Trim();
            model.STOREROOM_ID = cmbSTOREROOM_ID.SelectedValue.ToString().Trim();
            model.UNITS = Int32.Parse(txtUNITS.Text.Trim().Replace(",", ""));

            ReturnValue rvReturnValue = bll_M013_STORAGEOUTPUT.CheckUnits(model);

            if (rvReturnValue.ErrorFlag == false)
            {
                Method.MessageShow(rvReturnValue.ErrorID);
                return false;
            }
            if (0 == rvReturnValue.ResultDataSet.Tables[0].Rows.Count)
            {
                Method.MessageShow("W11025");
                cmbSTOREROOM_ID.Focus();
                cmbSTOREROOM_ID.SelectAll();
                return false;
            }
            if (Int32.Parse(txtUNITS.Text.Trim().Replace(",","")) >
                Int32.Parse(rvReturnValue.ResultDataSet.Tables[0].Rows[0]["UNITS"].ToString().Trim()))
            {
                Method.MessageShow("W11026");
                txtUNITS.Focus();
                txtUNITS.SelectAll();
                return false;
            }

            return true;
        }
        /// <summary>	
        /// <p><b>メソッド名:</b>AddRowToGird</p>	
        /// <p><b>概要説明  :</b>a new row add to grid</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修正履歴  :</b></p>	
        /// </summary>
        private void AddRowToGird()
        {
            for (int i = 0; i < grdmentTempBillInfo.Rows.Count; i++)
            {
                if (txtGOODS_ID.Text.Trim() ==
                    grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value.ToString().Trim())
                {
                    grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value =
                        txtGOODS_ID.Text.Trim();
                    grdmentTempBillInfo.Rows[i].Cells["GOODS_NM"].Value =
                        txtGOODS_NM.Text.Trim();
                    grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value =
                        NumPriceFormat( txtUNITS.Text.Trim().Replace(",",""));
                    grdmentTempBillInfo.Rows[i].Cells["STOREROOM_ID"].Value =
                        cmbSTOREROOM_ID.SelectedValue.ToString().Trim();
                    grdmentTempBillInfo.Rows[i].Cells["BUSINESS_TIME"].Value =
                        txtBUSINESS_TIME.Text.Trim();
                    grdmentTempBillInfo.Rows[i].Cells["MEMO"].Value =
                        rtbSTORAGEMEMO.Text.Trim();
                    return;
                }
            }

            grdmentTempBillInfo.Rows.Insert(0,
                (grdmentTempBillInfo.Rows.Count + 1).ToString(),
                txtGOODS_ID.Text.Trim(),
                txtGOODS_NM.Text.Trim(), NumPriceFormat(txtUNITS.Text.Trim().Replace(",", "")),
                cmbSTOREROOM_ID.SelectedValue.ToString().Trim(),
                txtBUSINESS_TIME.Text.Trim(), "删除", rtbSTORAGEMEMO.Text.Trim());
            grpTempBillInfo.Text = "临时货单信息" + "  共" +
                grdmentTempBillInfo.Rows.Count.ToString() + "件";
            if (grdmentTempBillInfo.Rows.Count > 17)
            {
                grdmentTempBillInfo.Columns["UNITS"].Width = 83;                
            }
            else
            {
                grdmentTempBillInfo.Columns["UNITS"].Width = 100;
            }
        }
        /// <summary>	
        /// <p><b>メソッド名:</b>NumPriceFormat</p>	
        /// <p><b>概要説明  :</b>num and price date's format</p>	
        /// <p><b>作成者	:</b>赫強</p>	
        /// <p><b>作成日	:</b>2008/09/03</p>	
        /// <p><b>修正履歴  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strValue">没有格式化的字符串</param>	
        /// <returns type="string">格式化后的字符串</returns>
        protected string NumPriceFormat(string strValue)
        {
            string strTemp = strValue;
            if (strValue.Length > 6)
            {
                strTemp = strValue.Substring(0, strValue.Length - 6) + ","
                    + strValue.Substring((strValue.Substring(0, strValue.Length - 6)).Length, 3)
                    + "," + strValue.Substring(strValue.Length - 3, 3);

            }
            else if (strValue.Length > 3)
            {
                strTemp = strValue.Substring(0, strValue.Length - 3) + ","
                + strValue.Substring((strValue.Substring(0, strValue.Length - 3)).Length, 3);
            }
            return strTemp;
        }

        #endregion

        #region Event

        private void M009_STORAGE_Load(object sender, EventArgs e)
        {
            InitProcess();
            txtGOODS_ID.Focus();
        }

        //private void grdmentTempBillInfo_SelectionChanged(object sender, EventArgs e)
        //{
        //    if (grdmentTempBillInfo.CurrentRow == null)
        //    {
        //        return;
        //    }

        //    txtGOODS_ID.Text =
        //        grdmentTempBillInfo.CurrentRow.Cells["GOODS_ID"].Value.ToString();
        //    txtGOODS_NM.Text =
        //        grdmentTempBillInfo.CurrentRow.Cells["GOODS_NM"].Value.ToString();
        //    txtUNITS.Text =
        //        grdmentTempBillInfo.CurrentRow.Cells["UNITS"].Value.ToString();
        //    dtpBUSINESS_TIME.Text =
        //        grdmentTempBillInfo.CurrentRow.Cells["BUSINESS_TIME"].Value.ToString();
        //    rtbSTORAGEMEMO.Text =
        //        grdmentTempBillInfo.CurrentRow.Cells["MEMO"].Value.ToString();

        //    for (int i = 0; i < cmbSTOREROOM_ID.Items.Count; i++)
        //    {
        //        cmbSTOREROOM_ID.SelectedIndex = i;
        //        if (cmbSTOREROOM_ID.SelectedValue.ToString() ==
        //            grdmentTempBillInfo.CurrentRow.Cells["STOREROOM_ID"].Value.ToString())
        //        {
        //            return;
        //        }
        //    }
        //}
        private void grdmentTempBillInfo_ButtonClick(object sender, DataGridViewCellEventArgs e)
        {
            int intColumnIndex = e.ColumnIndex;
            if (intColumnIndex == 6 && e.RowIndex != -1)
            {
                if (Method.MessageShow("Q22007") == DialogResult.Yes)
                {
                    grdmentTempBillInfo.Rows.RemoveAt(
                        grdmentTempBillInfo.CurrentRow.Index);
                    grpTempBillInfo.Text = "临时入库信息" + "  共" +
                grdmentTempBillInfo.Rows.Count.ToString() + "件";
                }
            }
            if (0 == grdmentTempBillInfo.Rows.Count)
            {
                grpTempBillInfo.Text = "临时入库信息";
            }
        }      
       
        protected override void AllTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            base.AllTextBox_KeyDown(sender, e);
        }
        private void AllTextBox_KeyPrecess(object sender, KeyPressEventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim();
            switch (((TextBox)sender).Name)
            {
                case "txtGOODS_ID":
                    FormBase.KeyPress(e, InputType.Tel);
                    break;
                case "txtUNITS":
                    FormBase.KeyPress(e, InputType.Num);
                    break;
            }
        }
        private void AllTextBox_GotFocus(object sender, EventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim();
            switch (((TextBox)sender).Name)
            {
                case "txtGOODS_ID":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    break;
                case "txtGOODS_NM":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Hiragana;
                    break;
                case "txtUNITS":
                    ((TextBox)sender).SelectAll();
                    ((TextBox)sender).ImeMode = ImeMode.Disable;
                    ((TextBox)sender).Text =
                        ((TextBox)sender).Text.Replace(",", "");
                    break;               
            }
        }
        private void AllTextBox_LostFocus(object sender, EventArgs e)
        {
            string strValue = ((TextBox)sender).Text.Trim();
            switch (((TextBox)sender).Name)
            {
                case "txtUNITS":
                    ((TextBox)sender).Text =
                        NumPriceFormat(((TextBox)sender).Text.Trim());
                        
                    break;
            }
        }

        private void AllButton_Click(object sender, EventArgs e)
        {
            if (Cursor.Current == Cursors.WaitCursor)
            {
                return;
            }
            Cursor.Current = Cursors.WaitCursor;

            string strButtonName = ((Button)sender).Name;

            switch (strButtonName)
            {
                #region btnGoodsIDSearch
                case "btnGoodsIDSearch":
                    {
                        M007_GOODS mstr_M007_GOODS = new M007_GOODS(true);
                        string strGoodID = "";
                        string strGoodNM = "";
                        mstr_M007_GOODS.StartPosition = FormStartPosition.CenterScreen;
                        mstr_M007_GOODS.ShowDialog(ref strGoodID, ref strGoodNM);
                        txtGOODS_ID.Text = strGoodID.Trim();
                        txtGOODS_NM.Text = strGoodNM.Trim();
                    }
                    break;
                #endregion

                #region btnTempAdd
                case "btnTempAdd":
                    if (CheckProcessLoop(enumOperation.Initial) == false)
                    {
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                    AddRowToGird();
                    break;
                #endregion

                #region btnAdd
                case "btnAdd":
                    if (CheckProcessLoop(enumOperation.Add) == false)
                    {
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                    if (0 == grdmentTempBillInfo.Rows.Count)
                    {
                        Method.MessageShow("W11001");
                        grdmentTempBillInfo.Focus();
                        Cursor.Current = Cursors.Default;
                        return;
                    }                    
                    if (Method.MessageShow("Q12009") == DialogResult.Yes)
                    { 
                        MODEL.MOD_M010_BILL modelBill =
                            new XiaoGang.Soft.XGWMS.MODEL.MOD_M010_BILL();
                        modelBill.UPDATER_ID = GlobalVal.gloUserInfo.UPDATER_ID.Trim();
                        modelBill.TERMINAL_CD = GlobalVal.gloUserInfo.TERMINAL_CD.Trim();
                        string strBillID = bll_STORAGE.GetBillID(modelBill);
                        if (strBillID.Trim().Length != 12)
                        {
                            Method.MessageShow(strBillID.Trim());
                            Cursor.Current = Cursors.Default;
                            return;
                        }

                        for (int i = 0; i < grdmentTempBillInfo.Rows.Count; i++)
                        {
                            string strReturn = "";

                            #region INSERT INTO STORAGE
                            MODEL.MOD_M009_STORAGE modelSTORAGE =
                                new XiaoGang.Soft.XGWMS.MODEL.MOD_M009_STORAGE();
                            
                            //入庫
                            if (rabIN.Checked == true && rabOUT.Checked == false)
                            {
                                modelSTORAGE.UPDATER_ID = GlobalVal.gloUserInfo.UPDATER_ID.Trim();
                                modelSTORAGE.TERMINAL_CD = GlobalVal.gloUserInfo.TERMINAL_CD.Trim();
                                modelSTORAGE.STORAGE_ID = "";//采番
                                modelSTORAGE.STOREROOM_ID =
                                    grdmentTempBillInfo.Rows[i].Cells["STOREROOM_ID"].Value.ToString();
                                modelSTORAGE.UNITS =
                                    Int32.Parse(grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value.ToString().Replace(",", ""));
                                modelSTORAGE.GOODS_ID =
                                    grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value.ToString();
                                modelSTORAGE.MEMO =
                                    grdmentTempBillInfo.Rows[i].Cells["MEMO"].Value.ToString();

                                strReturn = bll_STORAGE.InsertProcess(modelSTORAGE);
                            }
                            //出庫
                            if (rabIN.Checked == false && rabOUT.Checked == true)
                            {
                                modelSTORAGE.UPDATER_ID = GlobalVal.gloUserInfo.UPDATER_ID.Trim();
                                modelSTORAGE.TERMINAL_CD = GlobalVal.gloUserInfo.TERMINAL_CD.Trim();
                                modelSTORAGE.TRANS_STATE = "2";
                                modelSTORAGE.STOREROOM_ID =
                                    grdmentTempBillInfo.Rows[i].Cells["STOREROOM_ID"].Value.ToString();
                                modelSTORAGE.UNITS =
                                    Int32.Parse(grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value.ToString().Replace(",", ""));
                                modelSTORAGE.GOODS_ID =
                                    grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value.ToString();
                                modelSTORAGE.MEMO = "";

                                strReturn = bll_M013_STORAGEOUTPUT.UpdateStorageProcess(modelSTORAGE);
                            }
                            //Message
                            if (strReturn.Trim() != "0")
                            {
                                Method.MessageShow(strReturn.Trim());
                                Cursor.Current = Cursors.Default;
                                return;
                            }
                            #endregion

                            #region INSERT INTO BILL
                            strReturn = "";
                            modelBill.TRANS_STATE = "1";
                            modelBill.BILL_ID = strBillID;
                            modelBill.GOODS_ID =
                                grdmentTempBillInfo.Rows[i].Cells["GOODS_ID"].Value.ToString();
                            //黑
                            if (rabBlack.Checked == true && rabRed.Checked == false)
                            {
                                modelBill.RED_BLACK = "0";
                            }
                            //紅
                            if (rabBlack.Checked == false && rabRed.Checked == true)
                            {
                                modelBill.RED_BLACK = "1";
                            }
                            //入庫
                            if (rabIN.Checked == true && rabOUT.Checked == false)
                            {
                                modelBill.IN_OUT = "0";
                            }
                            //出庫
                            if (rabIN.Checked == false && rabOUT.Checked == true)
                            {
                                modelBill.IN_OUT = "1";
                            }
                            modelBill.UNITS =
                                Int32.Parse(grdmentTempBillInfo.Rows[i].Cells["UNITS"].Value.ToString().Replace(",", ""));
                            modelBill.BUSINESS_TIME = txtBUSINESS_TIME.Text.Trim();
                            modelBill.MEMO = rtbBILLMEMO.Text.Trim();

                            strReturn = bll_STORAGE.InsertProcess(modelBill);
                            if (strReturn.Trim() != "0")
                            {
                                Method.MessageShow(strReturn.Trim());
                                Cursor.Current = Cursors.Default;
                                return;
                            }

                            #endregion
                        }
                    }
                    Method.MessageShow("I11001");
                    grdmentTempBillInfo.Rows.Clear();
                    grpTempBillInfo.Text = "临时货单信息";
                    ClearControl();
                    txtGOODS_ID.Focus();
                    break;
                #endregion
            }
            Cursor.Current = Cursors.Default;
        }

        private void dtpBUSINESS_TIME_GotFocus(object sender, EventArgs e)
        {
            dtpBUSINESS_TIME.Select();
        }

        private void cmbSTOREROOM_ID_GotFocus(object sender, EventArgs e)
        {            
            cmbSTOREROOM_ID.SelectAll();
        }

        private void AllRichTextBox_GotFocus(object sender, EventArgs e)
        {
            string strControlName = ((RichTextBox)sender).Name;
            switch (strControlName)
            {
                case "rtbSTORAGEMEMO":
                    rtbSTORAGEMEMO.SelectAll();
                    rtbSTORAGEMEMO.ImeMode = ImeMode.Hiragana;
                    break;
                case "rtbBILLMEMO":
                    rtbBILLMEMO.SelectAll();
                    rtbBILLMEMO.ImeMode = ImeMode.Hiragana;
                    break;
            }
            
        }

        private void dtpBUSINESS_TIME_CloseUp(object sender, EventArgs e)
        {
            txtBUSINESS_TIME.Text = Method.TimeFormat( dtpBUSINESS_TIME.Value.ToString("yyyyMMdd"));
        }

        private void AllRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (rabIN.Checked == true && rabOUT.Checked == false)
            {
                btnAdd.Text = "入庫";
            }
            if (rabIN.Checked == false && rabOUT.Checked == true)
            {
                btnAdd.Text = "出庫";
            }
        }

        #endregion
    }
}